home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / uwpc201.zip / UW-SRC.ZIP / MAIN.CPP < prev    next >
C/C++ Source or Header  |  1991-11-03  |  11KB  |  360 lines

  1. //-------------------------------------------------------------------------
  2. //
  3. // MAIN.CPP - Main module for UW/PC Version 2.
  4. // 
  5. //  This file is part of UW/PC - a multi-window comms package for the PC.
  6. //  Copyright (C) 1990-1991  Rhys Weatherley
  7. //
  8. //  This program is free software; you can redistribute it and/or modify
  9. //  it under the terms of the GNU General Public License as published by
  10. //  the Free Software Foundation; either version 1, or (at your option)
  11. //  any later version.
  12. //
  13. //  This program is distributed in the hope that it will be useful,
  14. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. //  GNU General Public License for more details.
  17. //
  18. //  You should have received a copy of the GNU General Public License
  19. //  along with this program; if not, write to the Free Software
  20. //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. //
  22. // Revision History:
  23. // ================
  24. //
  25. //  Version  DD/MM/YY  By  Description
  26. //  -------  --------  --  --------------------------------------
  27. //    1.0    23/03/91  RW  Original Version of MAIN.CPP
  28. //    1.1    05/05/91  RW  Clean up and begin to add file transfers.
  29. //    1.2    08/06/91  RW  Add cut/paste and mouse support to UW/PC.
  30. //    1.3    27/09/91  RW  Add ALT-W for "next window" key.
  31. //
  32. // You may contact the author by:
  33. // =============================
  34. //
  35. //  e-mail: rhys@cs.uq.oz.au
  36. //    mail: Rhys Weatherley
  37. //          5 Horizon Drive
  38. //          Jamboree Heights
  39. //          Queensland 4074
  40. //        Australia
  41. //
  42. //-------------------------------------------------------------------------
  43.  
  44. #include <stdio.h>        // Standard I/O routines.
  45. #include "screen.h"        // Screen accessing routines.
  46. #include "client.h"        // Client control routines.
  47. #include "uw.h"            // UW protocol routines.
  48. #include "keys.h"        // Keyboard handling routines.
  49. #include "config.h"        // Configuration routines.
  50. #include "timer.h"        // System timer routines.
  51. #include "dialog.h"        // Dialog box routines.
  52. #include "files.h"        // File transfer routines.
  53. #include "comms.h"        // Communications routines.
  54. #include "clipbd.h"        // Clipboard handling routines.
  55. #include "mouse.h"        // Mouse handling routines.
  56. #include <dos.h>        // "delay" is defined here.
  57. #include <string.h>        // String handling routines.
  58.  
  59. #pragma    warn    -par
  60.  
  61. //
  62. // Define some useful macros for screen access.
  63. //
  64. #define    SCRN_WIDTH    (HardwareScreen.width)
  65. #define SCRN_HEIGHT    (HardwareScreen.height)
  66. #define    ATTR(x)        (HardwareScreen.attributes[(x)])
  67.  
  68. //
  69. // Define the title to be displayed for this module.
  70. //
  71. char    *TitleString = 
  72.     "UW/PC version 2.01, Copyright (C) 1990-1991 Rhys Weatherley\n"
  73.     "UW/PC comes with ABSOLUTELY NO WARRANTY; see the file COPYING for details.\n"
  74.     "This is free software, and you are welcome to redistribute it\n"
  75.     "under certain conditions; see the file COPYING for details.\n\n"
  76.         "Press ALT-Z for help on special keys.\n\n";
  77.  
  78. unsigned cdecl    _stklen=8192;
  79.  
  80. int    DebugMode;
  81. FILE    *DebugFile;
  82.  
  83. int    main    (int argc,char *argv[])
  84. {
  85.   char *mesg;
  86.   DebugMode = 0;
  87.   if (argc > 1 && !strcmp (argv[1],"-debug"))
  88.     {
  89.       // Open a debugging file to help me with user problems //
  90.       if ((DebugFile = fopen ("UWDEBUG.OUT","wb")) != NULL)
  91.         DebugMode = 1;
  92.     } /* if */
  93.   UWConfig.doconfig (argv[0]);    // Configure the program as necessary.
  94.   if (!HardwareScreen.init (0))
  95.     {
  96.       fprintf (stderr,"Cannot initialise screen - not enough memory\n");
  97.       return (0);
  98.     }
  99.   HardwareScreen.scroll (0,0,SCRN_WIDTH - 1,SCRN_HEIGHT - 2,0,
  100.                ATTR(ATTR_NORMAL));
  101.   HardwareScreen.scroll (0,SCRN_HEIGHT - 1,SCRN_WIDTH - 1,SCRN_HEIGHT - 1,0,
  102.           (UWConfig.DisableStatusLine ? 0x07 : ATTR(ATTR_STATUS)));
  103.   HardwareScreen.cursor (0,4);
  104.   HardwareScreen.shape ((CursorShapes)UWConfig.CursorSize);
  105.   if (UWConfig.EnableMouse)
  106.     UWConfig.EnableMouse = InitMouse ();
  107.   InitKeyboard ();
  108.   InitTimers ();
  109.   mesg = UWMaster.start ();
  110.   TermTimers ();
  111.   TermKeyboard ();
  112.   if (UWConfig.EnableMouse)
  113.     TermMouse ();
  114.   HardwareScreen.term ();
  115.   if (mesg)
  116.     fprintf (stderr,"%s\n",mesg);
  117.   if (DebugMode)
  118.     fclose (DebugFile);
  119.   return (0);
  120. } // main //
  121.  
  122. //
  123. // Send a command-line for the DSZ program to do a ZMODEM file transfer.
  124. //
  125. static    void    SendZModemCommand (char *cmd,char *file)
  126. {
  127.   static char cmdline[256];
  128.   sprintf (cmdline,"%s port %d portx %x,%d ha off %s %s",
  129.           UWConfig.ZModemCommand,
  130.           UWConfig.ComPort,
  131.           comports[UWConfig.ComPort - 1],
  132.         4 - ((UWConfig.ComPort - 1) % 2),cmd,file);
  133.   UWMaster.direct (1);        // Turn on direct communications.
  134.   UWMaster.jumpdos (cmdline);    // Do the ZMODEM command line.
  135.   UWMaster.direct (0);        // Turn off direct communications.
  136. } // SendZModemCommand //
  137.  
  138. //
  139. // Define the query dialog boxes used by this module.
  140. //
  141.  
  142. class    QuitQueryBox : public UWQueryBox {
  143.  
  144. public:
  145.  
  146.     QuitQueryBox (UWDisplay *wind) :
  147.         UWQueryBox (wind,"Exit UW/PC? Yes or No",21) {};
  148.  
  149.     virtual    void    process    (int index)
  150.           { if (index < 2) UWMaster.terminate = 1;  // Kill UW/PC.
  151.             terminate (); };
  152.  
  153. };
  154.  
  155. class    ExitQueryBox : public UWQueryBox {
  156.  
  157. public:
  158.  
  159.     ExitQueryBox (UWDisplay *wind) :
  160.         UWQueryBox (wind,"Exit? Yes or No",15) {};
  161.  
  162.     virtual    void    process    (int index)
  163.           { if (index < 2) UWMaster.exitmulti = 1; // Exit protocol 1.
  164.             terminate (); };
  165.  
  166. };
  167.  
  168. class    HangupQueryBox : public UWQueryBox {
  169.  
  170. public:
  171.  
  172.     HangupQueryBox (UWDisplay *wind) :
  173.         UWQueryBox (wind,"Hangup? Yes or No",17) {};
  174.  
  175.     virtual    void    process    (int index)
  176.           { if (index < 2) UWMaster.sendbreak (); // Send a BREAK.
  177.             terminate (); };
  178.  
  179. };
  180.  
  181. class    BreakQueryBox : UWQueryBox {
  182.  
  183. public:
  184.  
  185.     BreakQueryBox (UWDisplay *wind) :
  186.         UWQueryBox (wind,"Send BREAK? Yes or No",21) {};
  187.  
  188.     virtual    void    process    (int index)
  189.           { if (index < 2) UWMaster.hangup ();    // Hangup the modem.
  190.             terminate (); };
  191.  
  192. };
  193.  
  194. static    char    *asciimsgs[] =
  195.      {"Enter name of file to upload, ^X to clear line, or ESC to abort.",
  196.       "Enter name of file to download, ^X to clear line, or ESC to abort.",
  197.       "Enter name of capture file, ^X to clear line, or ESC to abort."};
  198.  
  199. class    AsciiEditBox : public UWEditBox {
  200.  
  201. protected:
  202.  
  203.     int    kind;
  204.  
  205. public:
  206.  
  207.     AsciiEditBox (UWDisplay *wind,int Kind) :
  208.         UWEditBox (wind,asciimsgs[Kind],MAX_EDIT_SIZE)
  209.             { kind = Kind; };
  210.  
  211.     virtual void    process (int esc)
  212.           { terminate ();
  213.             if (!esc && buffer[0] != '\0')
  214.               new UWAsciiFileTransfer (window,kind,buffer);
  215.           };
  216. };
  217.  
  218. class    FileEditBox : public UWEditBox {
  219.  
  220. protected:
  221.  
  222.     int    upload;
  223.     int    kind;
  224.  
  225. public:
  226.  
  227.     FileEditBox (UWDisplay *wind,int Upload,int Kind) :
  228.         UWEditBox (wind,asciimsgs[!Upload],MAX_EDIT_SIZE)
  229.             { kind = Kind; upload = Upload; };
  230.  
  231.     virtual void    process (int esc)
  232.           { terminate ();
  233.             if (!esc && buffer[0] != '\0')
  234.               new UWXYFileTransfer (window,kind,!upload,buffer);
  235.           };
  236. };
  237.  
  238. class    ZModemEditBox : public UWEditBox {
  239.  
  240. public:
  241.  
  242.     ZModemEditBox (UWDisplay *wind) :
  243.         UWEditBox (wind,asciimsgs[0],MAX_EDIT_SIZE) {};
  244.  
  245.     virtual void    process (int esc)
  246.           { terminate ();
  247.             if (!esc && buffer[0] != '\0')
  248.               {
  249.                 SendZModemCommand ("sz -b",buffer);
  250.             send ('\r');    // Send ^M to get command line back.
  251.               }
  252.           };
  253. };
  254.  
  255. class    FileQueryBox : public UWQueryBox {
  256.  
  257. protected:
  258.  
  259.     int    upload;
  260.  
  261. public:
  262.  
  263.     FileQueryBox (UWDisplay *wind,int Upload) :
  264.         UWQueryBox (wind,UWMaster.protocol == 0 ?
  265.             "[A]scii, [X]modem or [Z]modem?" :
  266.             "[A]scii, [X]modem",
  267.             UWMaster.protocol == 0 ? 30 : 20,
  268.             UWMaster.protocol == 0 ? "\033aAxXzZ" :
  269.                 "\033aAxX")
  270.             { upload = Upload; };
  271.  
  272.     virtual    void    process    (int index)
  273.           { if (index < 1)
  274.               terminate ();
  275.              else if (index < 3)
  276.               {
  277.                 terminate ();
  278.             new AsciiEditBox (window,(upload ? ASCII_UPLOAD
  279.                              : ASCII_DOWNLOAD));
  280.               }
  281.              else if (index < 5)
  282.               {
  283.                 terminate ();
  284.             new FileEditBox (window,upload,XMOD_ORIGINAL);
  285.               }
  286.              else if (index < 7)
  287.               {
  288.